package com.lbssoft.gpsbd.dao;

import com.lbssoft.gpsbd.model.Log;
import com.lbssoft.gpsbd.model.LoginLog;
import com.lbssoft.gpsbd.model.Media;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface MediaMapper {

	/**
	 * 写入媒体
	 * @param media
     */
	@Insert("INSERT INTO lbs_medias(deviceId,type,file) VALUES(#{deviceId},#{type},#{file});")
	void add(Media media);

	/**
	 * 根据设备id获取媒体信息
	 * @param deviceId
	 * @return
     */
	@Select("SELECT t.id,t.deviceId,t.type,t.time,concat('oss.taiyangos.com/device-media/',a.imei,'/',t.file) as file FROM lbs_medias t LEFT JOIN lbs_devices a ON t.deviceid = a.id WHERE t.deviceId =   #{deviceId} ORDER BY t.id DESC")
	List<Media> getMedias(@Param("deviceId") long deviceId);

}
